﻿<%@ WebHandler Language="C#" Class="manageComplaints" %>

using System;
using System.Web;
using System.Data;

using AMCBO;
using AMCOBJ;

public class manageComplaints : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        splComplaintOBJ OBJComp = new splComplaintOBJ();
        splComplaintsBO BOComp = new splComplaintsBO();
        if (!string.IsNullOrEmpty(context.Request.QueryString["case"]))
        {
            string swch = context.Request.QueryString["case"];
            switch (swch)
            {
                case "insert":
                    int x = 0;
                    if (!string.IsNullOrEmpty(context.Request.QueryString["cname"]))
                    {
                        OBJComp.CusName = context.Request.QueryString["cname"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["caddress"]))
                    {
                        OBJComp.CusAddress = context.Request.QueryString["caddress"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["croute"]))
                    {
                        OBJComp.CusRoute = context.Request.QueryString["croute"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["clocation"]))
                    {
                        OBJComp.CusLocation = context.Request.QueryString["clocation"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["clandmark"]))
                    {
                        OBJComp.CusLandmark = context.Request.QueryString["clandmark"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["cstate"]))
                    {
                        OBJComp.CusState = context.Request.QueryString["cstate"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["cpostcode"]))
                    {
                        OBJComp.Postcode = context.Request.QueryString["cpostcode"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["cmobile"]))
                    {
                        OBJComp.Mobile = context.Request.QueryString["cmobile"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["clandline"]))
                    {
                        OBJComp.Landline = context.Request.QueryString["clandline"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["cemail"]))
                    {
                        OBJComp.Email = context.Request.QueryString["cemail"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["pcate"]))
                    {
                        OBJComp.Category = context.Request.QueryString["pcate"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["pname"]))
                    {
                        OBJComp.Product = context.Request.QueryString["pname"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["pmodal"]))
                    {
                        OBJComp.Modal = context.Request.QueryString["pmodal"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["pcomp"]))
                    {
                        OBJComp.Compressor = context.Request.QueryString["pcomp"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["pindoor"]))
                    {
                        OBJComp.Indoor = context.Request.QueryString["pindoor"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["poutdoor"]))
                    {
                        OBJComp.Outdoor = context.Request.QueryString["poutdoor"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["compdesc"]))
                    {
                        OBJComp.CompDesc = context.Request.QueryString["compdesc"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["technician"]))
                    {
                        OBJComp.Technician = context.Request.QueryString["technician"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["scheduledt"]))
                    {
                        OBJComp.ScheduleDt = context.Request.QueryString["scheduledt"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["status"]))
                    {
                        OBJComp.Status = context.Request.QueryString["status"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["isspare"]))
                    {
                        OBJComp.IsSpare = context.Request.QueryString["isspare"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["sparedetails"]))
                    {
                        OBJComp.SpareDetails = context.Request.QueryString["sparedetails"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["issueid"]))
                    {
                        OBJComp.IssueID = context.Request.QueryString["issueid"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["cusid"]))
                    {
                        OBJComp.CusID = new Guid(context.Request.QueryString["cusid"]);
                    }
                    HttpCookie oCookieID = (HttpCookie)context.Request.Cookies["username"];
                    if (oCookieID.Value != string.Empty)
                    {
                        OBJComp.UserName = oCookieID.Value.ToString();
                    }
                    try
                    {
                        x = BOComp.insertComplaintsNew(OBJComp);
                        if (x == 0)
                        {
                            context.Response.Write("y");
                        }
                        else
                        {
                            context.Response.Write("n");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    break;
                case "getCusData":
                    if (!string.IsNullOrEmpty(context.Request.QueryString["cusid"]))
                    {
                        string output = string.Empty;
                        OBJComp.CustomerID = context.Request.QueryString["cusid"];
                        DataTable dt = new DataTable();
                        dt = BOComp.getCustomerDataByID(OBJComp);
                        if (dt.Rows.Count > 0)
                        {
                            output = "[";
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                output += "{\"name\":\"" + dt.Rows[i]["customerName"] +
                                    "\",\"address\":\"" + dt.Rows[i]["cus_Address1"].ToString().Replace("\n"," ") +
                                    "\",\"city\":\"" + dt.Rows[i]["cus_City"] +
                                    "\",\"state\":\"" + dt.Rows[i]["cus_State"] +
                                    "\",\"postcode\":\"" + dt.Rows[i]["cus_Postcode"] +
                                    "\",\"mobile\":\"" + dt.Rows[i]["cus_Mobile"] +
                                    "\",\"landline\":\"" + dt.Rows[i]["cus_AltPhone"] +
                                    "\",\"email\":\"" + dt.Rows[i]["cus_Email"] +
                                    //"\",\"cusguid\":\"" + dt.Rows[i]["cus_guid"] +
                                    //"\",\"prevImgFId\":\"" + boTheme[i].PreviewImageFileID +
                                    //"\",\"cssFId\":\"" + boTheme[i].CSSFileID +
                                    "\"},";
                            }
                            if (output[output.Length - 1] == ',')
                            {
                                output = output.Substring(0, output.Length - 1);
                            }
                            output += "]";
                        }
                        context.Response.Write(output);
                    }
                    break;
                case "update":
                    int w = 0;
                    if (!string.IsNullOrEmpty(context.Request.QueryString["compid"]))
                    {
                        OBJComp.CompID = new Guid(context.Request.QueryString["compid"]);
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["compdesc"]))
                    {
                        OBJComp.CompDesc = context.Request.QueryString["compdesc"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["technician"]))
                    {
                        OBJComp.Technician = context.Request.QueryString["technician"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["scheduledt"]))
                    {
                        OBJComp.ScheduleDt = context.Request.QueryString["scheduledt"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["status"]))
                    {
                        OBJComp.Status = context.Request.QueryString["status"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["isspare"]))
                    {
                        OBJComp.IsSpare = context.Request.QueryString["isspare"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["sparedetails"]))
                    {
                        OBJComp.SpareDetails = context.Request.QueryString["sparedetails"];
                    }
                    if (!string.IsNullOrEmpty(context.Request.QueryString["isfix"]))
                    {
                        OBJComp.IsFixed = Convert.ToInt32(context.Request.QueryString["isfix"]);
                    }
                    HttpCookie tCookieID = (HttpCookie)context.Request.Cookies["username"];
                    if (tCookieID.Value != string.Empty)
                    {
                        OBJComp.UserName = tCookieID.Value.ToString();
                    }
                    try
                    {
                        w = BOComp.updateComplaintNew(OBJComp);
                        if (w == 0)
                        {
                            context.Response.Write("y");
                        }
                        else
                        {
                            context.Response.Write("n");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    break;
                default:
                    break;
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}